package com.guo.pet_store.admin.service;

import com.guo.pet_store.admin.dao.TypeRepository;
import com.guo.pet_store.admin.pojo.PetType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl implements TypeService{
    @Autowired
    TypeRepository typeRepository;
    @Override
    public Page<PetType> listType(Pageable pageable) {
        return typeRepository.findAll(pageable);
    }

    @Override
    public List<PetType> listType() {
        return typeRepository.findAll();
    }

    @Override
    public PetType saveType(PetType type) {
        return typeRepository.save(type);
    }

    @Override
    public PetType selectAType(Long typeId) {
        return typeRepository.getOne(typeId);
    }

    @Override
    public PetType getAPetType(Long id) {
        return typeRepository.getOne(id);
    }

    @Override
    public void editType(Long id, String name) {
        typeRepository.updateType(id,name);
    }

    @Override
    public void deleteType(Long typeId) {
        typeRepository.delete(typeRepository.getOne(typeId));
    }

    @Override
    public List<PetType> parentType() {
        return typeRepository.parentType();
    }

    @Override
    public List<PetType> sonType(Long parentId) {
        return typeRepository.sonType(parentId);
    }

    @Override
    public List<PetType> listSonType() {
        return typeRepository.listSonType();
    }
}
